package myky.com.doctorapp.ui;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import myky.com.doctorapp.R;
import myky.com.doctorapp.adapter.TabViewPagerAdapter;
import myky.com.doctorapp.entity.LoginEntity;
import myky.com.doctorapp.entity.LoginSuccessEntity;
import myky.com.doctorapp.entity.NewConsultListBean;
import myky.com.doctorapp.base.BaseActivity;
import myky.com.doctorapp.contract.PwLoginFragmentContract;
import myky.com.doctorapp.fragment.PnLoginFragment;
import myky.com.doctorapp.fragment.PwLoginFragment;
import myky.com.doctorapp.presenter.PwLoginFragmentPresenter;

import myky.com.doctorapp.utils.ILog;
import myky.com.doctorapp.utils.ToastUtils;

/**
 * @author Mr.li
 */
public class LoginActivity extends BaseActivity<PwLoginFragmentPresenter, LoginEntity.PayLoadBean> implements PwLoginFragmentContract.View {

    @BindView(R.id.case_title_white)
    RelativeLayout mCaseTitleWhite;
    @BindView(R.id.include_title_center_white)
    TextView mIncludeTitleCenterWhite;
    @BindView(R.id.include_title_right_text)
    TextView mIncludeTitleRightText;
    @BindView(R.id.include_title_right_rl)
    RelativeLayout mIncludeTitleRightRl;
    @BindView(R.id.case_title_white_rl)
    RelativeLayout mCaseTitleWhiteRl;
    @BindView(R.id.login_tabLayout_show)
    SlidingTabLayout mLoginTabLayoutShow;
    @BindView(R.id.login_viewPager)
    ViewPager mLoginViewPager;
    @BindView(R.id.otherLogin_wechat)
    ImageView mOtherLoginWechat;
    @BindView(R.id.otherLogin_qq)
    ImageView mOtherLoginQq;
    @BindView(R.id.activity_login)
    LinearLayout mActivityLogin;

    private Context mContext;
    private TabViewPagerAdapter mViewPagerAdapter;

    private List<String> tabLists = new ArrayList<>(16);
    private List<Fragment> fragments = new ArrayList<>(16);

    @Override
    public PwLoginFragmentPresenter getPresenter() {
        return new PwLoginFragmentPresenter();
    }

    @Override
    protected void reloadActivity() {

    }

    @Override
    protected View injectTarget() {
        return null;
    }

    @Override
    protected void initData() {
        if (tabLists.size() > 0) {
            mViewPagerAdapter = new TabViewPagerAdapter(getSupportFragmentManager(), fragments,tabLists);
            mLoginViewPager.setAdapter(mViewPagerAdapter);
            mLoginTabLayoutShow.setViewPager(mLoginViewPager);
            mLoginTabLayoutShow.setCurrentTab(0);
            mLoginViewPager.setCurrentItem(0);
        }
    }

    @Override
    protected void initView() {
        mContext = LoginActivity.this;
        mIncludeTitleRightRl.setVisibility(View.VISIBLE);
        mIncludeTitleRightText.setText("注册");
        tabLists.add("手机号登录");
        tabLists.add("账号密码登录");
        PnLoginFragment phoneNumberFragment = new PnLoginFragment();
        PwLoginFragment passwordLoginFragment = new PwLoginFragment();
        fragments.add(phoneNumberFragment);
        fragments.add(passwordLoginFragment);
    }

    @Override
    public int getContenView() {
        return R.layout.activity_login;
    }

    @Override
    public void showDataSuccess(LoginEntity.PayLoadBean datas) {

    }

    @Override
    public void loginFailed(String message) {

    }

    @Override
    public void loginSuccess(LoginSuccessEntity.PayLoadBean successEntity) {
        ILog.i(successEntity.getUser().toString());




    }

    @Override
    public void vlist(List<NewConsultListBean.PayLoadBean.SpecialistConsultsBean> consultsBeanList) {
        Toast.makeText(this, "认证成功", Toast.LENGTH_LONG).show();
    }

    @OnClick({R.id.case_title_white, R.id.include_title_right_text})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.case_title_white:
                finish();
                break;
            case R.id.include_title_right_text:
                ToastUtils.showAtCenter("点击了注册");
                break;
            default:
        }
    }
}
